<?php
#http://www.gen-x-design.com/demos/thumbnailer/ http://www.gen-x-design.com/projects/php-thumbnailer-class/
$_img           = 'sample.jpg';
$thumbsfolder   = '.';
$imagefolder    = '.';
$pics           = directory($imagefolder,"/\bjpg\b|\bjpeg\b/i");
include_once('thumbnail.inc.php');

foreach ($pics as $i)
  {
   $path = pathinfo($i);
   #file, width, height, quality, reflection, thumb folder;
    createthumb($i,150,150,33,1,$thumbsfolder);
  }


function createthumb($i,$w,$h,$q,$m,$tf){
$thumb = new Thumbnail($i);
$thumb->resize($w,$h);
$thumb->cropFromCenter(100);
if ($m) $thumb->createReflection(40,40,80,false,'#a4a4a4');
$path = pathinfo($i);
$thumb->save($tf.'/'. $path['filename'].'_tmb.jpg',$q);
$thumb->show();
}


function directory($dir,$filter)
{
  $handle=opendir($dir);
  $files=array();
  while (($file = readdir($handle))!==false)
  {
    $system=explode(".",$file);
    $path = pathinfo($file);
    if (preg_match($filter, $path['extension'])) {
      if (!preg_match('/_tmb$/i', $path['filename'])) {
        $files[] = $dir.'/'.$file ;
      }
    }
  }
closedir($handle);
return $files;
}
?>